﻿namespace MoveTest
{
    internal class Program
    {
        enum Direction
        {
            Up,
            Down,
            Left,
            Right
        }
        const int countOfTeast = 10;
        static void Main(string[] args)
        {
            //平均反应时间
            double reactionTime = 0;
            //统计循环开始的时间
            int countOfError = 0;
            //产生随机数
            Random rnd = new Random();
            for (int i = 0; i < countOfTeast; i++)
            {
                DateTime dataTimeStart = DateTime.Now;

                Console.Clear();
                Console.WriteLine($"现在正在第{i}次测试，总耗时{reactionTime}秒,共错误{countOfError}次");

                Direction direction = (Direction)rnd.Next(0, 4);
                Console.WriteLine(direction.ToString());
                bool flag = false;
                do
                {
                    var key = Console.ReadKey();
                    switch (direction)
                    {
                        case Direction.Up:
                            if (key.Key == ConsoleKey.UpArrow) flag = true;
                            break;
                        case Direction.Down:
                            if (key.Key == ConsoleKey.DownArrow) flag = true;
                            break;
                        case Direction.Left:
                            if (key.Key == ConsoleKey.LeftArrow) flag = true;
                            break;
                        case Direction.Right:
                            if (key.Key == ConsoleKey.RightArrow) flag = true;
                            break;
                    }
                    if (!flag) countOfError++;
                    else
                    {
                        reactionTime += (System.DateTime.Now - dataTimeStart).TotalSeconds;
                    }
                } while (!flag);
            }
            Console.Clear();
            Console.WriteLine($"总耗时{reactionTime}秒，共错误{countOfError}");
        }
    }
}